console.log("4RBush");
let utils = data["utils"];
let RBushItem = data["RBushItem"];
let RBU = data["RBU"];
let RBush = data["RBush"];

utils.extend(RBush.prototype, {

  _insert: function (item, level, isNode) {
    var toBBox = this.toBBox,
      bbox = isNode ? item : toBBox(item),
      insertPath = [],
      node = this._chooseSubtree(bbox, this.data, level, insertPath);
    if (node.children == undefined) {
      console.log("666666")
    }
    node.children.push(item);
    RBU.extend(node, bbox);
    for (; level >= 0 && insertPath[level].children.length > this._maxEntries;) {
      this._split(insertPath, level);
      level--;
    }
    this._apbb(bbox, insertPath, level);
  },
  _split: function (insertPath, level) {
    var node = insertPath[level],
      M = node.children.length,
      m = this._minEntries;
    this._csa(node, m, M);
    var splitIndex = this._chooseSplitIndex(node, m, M),
      newNode = RBU.createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
    newNode.height = node.height;
    newNode.leaf = node.leaf;
    RBU.calcBBox(node, this.toBBox);
    RBU.calcBBox(newNode, this.toBBox);
    level ? insertPath[level - 1].children.push(newNode) : this._splitRoot(node, newNode);
  },
  _splitRoot: function (node, newNode) {
    this.data = RBU.createNode([node, newNode]);
    this.data.height = node.height + 1;
    this.data.leaf = !1;
    RBU.calcBBox(this.data, this.toBBox);
  },
  _chooseSplitIndex: function (node, m, M) {
    var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;
    minOverlap = minArea = 1 / 0;
    for (i = m; i <= M - m; i++) {
      bbox1 = RBU.distBBox(node, 0, i, this.toBBox);
      bbox2 = RBU.distBBox(node, i, M, this.toBBox);
      overlap = RBU.intersectionArea(bbox1, bbox2);
      area = RBU.bboxArea(bbox1) + RBU.bboxArea(bbox2);
      if (overlap < minOverlap) {
        minOverlap = overlap;
        index = i;
        minArea = area < minArea ? area : minArea;
      } else if (overlap === minOverlap && area < minArea) {
        minArea = area;
        index = i;
      }
    }
    return index;
  },
  _csa: function (node, m, M) {
    var compareMinX = node.leaf ? this.compareMinX : RBU.compareNodeMinX,
      compareMinY = node.leaf ? this.compareMinY : RBU.compareNodeMinY,
      xMargin = this._allDM(node, m, M, compareMinX),
      yMargin = this._allDM(node, m, M, compareMinY);
    xMargin < yMargin && node.children.sort(compareMinX);
  },
  _allDM: function (node, m, M, compare) {
    node.children.sort(compare);
    var i, child, toBBox = this.toBBox,
      leftBBox = RBU.distBBox(node, 0, m, toBBox),
      rightBBox = RBU.distBBox(node, M - m, M, toBBox),
      margin = RBU.bboxMargin(leftBBox) + RBU.bboxMargin(rightBBox);
    for (i = m; i < M - m; i++) {
      child = node.children[i];
      RBU.extend(leftBBox, node.leaf ? toBBox(child) : child);
      margin += RBU.bboxMargin(leftBBox);
    }
    for (i = M - m - 1; i >= m; i--) {
      child = node.children[i];
      RBU.extend(rightBBox, node.leaf ? toBBox(child) : child);
      margin += RBU.bboxMargin(rightBBox);
    }
    return margin;
  },
  _apbb: function (bbox, path, level) {
    for (var i = level; i >= 0; i--) RBU.extend(path[i], bbox);
  },
  _condense: function (path) {
    for (var siblings, i = path.length - 1; i >= 0; i--)
      if (0 === path[i].children.length)
        if (i > 0) {
          siblings = path[i - 1].children;
          siblings.splice(siblings.indexOf(path[i]), 1);
        } else this.clear();
      else RBU.calcBBox(path[i], this.toBBox);
  }
});

return {
  "utils": utils,
  "RBushItem": RBushItem,
  "RBU": RBU,
  "RBush": RBush
}